<?php

namespace app\admin\controller;

use app\common\controller\AdminBase;

class Personnels extends AdminBase
{
    protected function _initialize()
    {
        parent::_initialize();
    }
    /**
     * 学员列表
     */
    public function index()
    {
        $param = $this->request->param();
        $where = [];
        if (isset($param['key'])) {
            if(check_mobile($param['key'])){
                $where['mobile'] = ['like', "%" . $param['key'] . "%"];
            }else{
                $where['username'] = ['like', "%" . $param['key'] . "%"];
            }
        }
        $list=model('Personnel')->where('Personnel_id',['>',0])->where($where)->paginate(config('page_number'));
        $page = input('page')?:0;
        return $this->fetch('index', ['list' =>$list,'page'=>$page,'user'=>$param['user'],'model'=>$param['model']]);
    }
    /**
     * 后台添加人才
     */
    public function add(){
            $param = $this->request->param();
            if($this->insert($param['model'], ['personnel_id'=>$param['personnel_id'],'group'=>$param['user']],$rule = true, $field = true) === true){
                insert_admin_log('添加成员');
                if($param['model']=='member'){
                    $this->success('添加成功', url('admin/member/index',['id'=>$param['user']]));
                }else{
                    $this->success('添加成功', url('admin/dorms/index',['id'=>$param['user']]));
                }
            }else{
                $this->error($this->errorMsg);
            }
        }

}
